home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / gg / ncurses-5.3.lha / ncurses-5.3 / c++ / cursesp.cc < prev    next >
C/C++ Source or Header  |  2002-10-24  |  4KB  |  131 lines

  1. // * this is for making emacs happy: -*-Mode: C++;-*-
  2. /****************************************************************************
  3.  * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc.         *
  4.  *                                                                          *
  5.  * Permission is hereby granted, free of charge, to any person obtaining a  *
  6.  * copy of this software and associated documentation files (the            *
  7.  * "Software"), to deal in the Software without restriction, including      *
  8.  * without limitation the rights to use, copy, modify, merge, publish,      *
  9.  * distribute, distribute with modifications, sublicense, and/or sell       *
  10.  * copies of the Software, and to permit persons to whom the Software is    *
  11.  * furnished to do so, subject to the following conditions:                 *
  12.  *                                                                          *
  13.  * The above copyright notice and this permission notice shall be included  *
  14.  * in all copies or substantial portions of the Software.                   *
  15.  *                                                                          *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
  17.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
  18.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
  19.  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
  20.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
  21.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
  22.  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
  23.  *                                                                          *
  24.  * Except as contained in this notice, the name(s) of the above copyright   *
  25.  * holders shall not be used in advertising or otherwise to promote the     *
  26.  * sale, use or other dealings in this Software without prior written       *
  27.  * authorization.                                                           *
  28.  ****************************************************************************/
  29.  
  30. /****************************************************************************
  31.  *   Author: Juergen Pfeifer, 1993, 1997                                    *
  32.  *   Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en             *
  33.  ****************************************************************************/
  34.  
  35. #include "internal.h"
  36. #include "cursesp.h"
  37. #include <string.h>
  38.  
  39. MODULE_ID("$Id: cursesp.cc,v 1.20 2002/07/13 11:35:08 juergen Exp $")
  40.  
  41. NCursesPanel* NCursesPanel::dummy = (NCursesPanel*)0;
  42.  
  43. void NCursesPanel::init() {
  44.   p = ::new_panel(w);
  45.   if (!p)
  46.     OnError(ERR);
  47.  
  48.   UserHook* hook = new UserHook;
  49.   hook->m_user  = NULL;
  50.   hook->m_back  = this;
  51.   hook->m_owner = p;
  52.   ::set_panel_userptr(p, (void *)hook);
  53. }
  54.  
  55. NCursesPanel::~NCursesPanel() {
  56.   UserHook* hook = (UserHook*)::panel_userptr(p);
  57.   assert(hook != 0 && hook->m_back==this && hook->m_owner==p);
  58.   delete hook;
  59.   ::del_panel(p);
  60.   ::update_panels();
  61. }
  62.  
  63. void
  64. NCursesPanel::redraw() {
  65.   PANEL *pan;
  66.  
  67.   pan = ::panel_above(NULL);
  68.   while (pan) {
  69.     ::touchwin(panel_window(pan));
  70.     pan = ::panel_above(pan);
  71.   }
  72.   ::update_panels();
  73.   ::doupdate();
  74. }
  75.  
  76. int
  77. NCursesPanel::refresh() {
  78.   ::update_panels();
  79.   return ::doupdate();
  80. }
  81.  
  82. int
  83. NCursesPanel::noutrefresh() {
  84.   ::update_panels();
  85.   return OK;
  86. }
  87.  
  88. void
  89. NCursesPanel::boldframe(const char *title, const char* btitle) {
  90.   standout();
  91.   frame(title, btitle);
  92.   standend();
  93. }
  94.  
  95. void
  96. NCursesPanel::frame(const char *title,const char *btitle) {
  97.   int err = OK;
  98.   if (!title && !btitle) {
  99.     err = box();
  100.   }
  101.   else {
  102.     err = box();
  103.     if (err==OK)
  104.       label(title,btitle);
  105.   }
  106.   OnError(err);
  107. }
  108.  
  109. void
  110. NCursesPanel::label(const char *tLabel, const char *bLabel) {
  111.   if (tLabel)
  112.     centertext(0,tLabel);
  113.   if (bLabel)
  114.     centertext(maxy(),bLabel);
  115. }
  116.  
  117. void
  118. NCursesPanel::centertext(int row,const char *label) {
  119.   if (label) {
  120.     int x = (maxx() - ::strlen(label)) / 2;
  121.     if (x<0)
  122.       x=0;
  123.     OnError(addstr(row, x, label, width()));
  124.   }
  125. }
  126.  
  127. int
  128. NCursesPanel::getKey(void) {
  129.   return getch();
  130. }
  131.